<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('京东推广全局设置')" />
    <th:block th:include="include :: bootstrap-editable-css" />

    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-switch/3.3.4/css/bootstrap3/bootstrap-switch.min.css" rel="stylesheet">

</head>
<body class="gray-bg">

<div class="container-div">

    <div class="row">
        <div class="col-sm-12" >
        <div class="col-sm-12 select-table table-striped" >

            <div class="btn-group-sm" id="toolbar-jd" role="group">
                <h3 >
                    全局设置
                </h3>
            </div>
            <table id="bootstrap-table" ></table>
        </div>
        <div class="col-sm-12 select-table table-striped"  >
            <div class="btn-group-sm" id="toolbar" role="group">
                <h3 >
                    新增商品
                </h3>
            </div>
            <table id="bootstrap-table-file"></table>
        </div>
        </div>

    </div>



</div>
</div>


<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-editable-js" />
<th:block th:include="include :: bootstrap-table-export-js" />
<script src="https://cdn.bootcss.com/bootstrap-switch/3.3.4/js/bootstrap-switch.min.js"></script>
<script >
    var ctx = "[[@{/}]]";
</script>
<script th:inline="javascript">
    //  var editFlag = [[${@permission.hasPermi('system:post:edit')}]];
    // var removeFlag = [[${@permission.hasPermi('system:post:remove')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "jd/global";


    $(function() {

        var options_jd = {
            id: "bootstrap-table",
            url : ctx + "jd/global" +"/list",
            toolbar:"toolbar-jd",
            removeUrl: prefix + "/delete/{id}",
            modalName: "京东推荐商品明细",
            height: $(window).height()/2 + 100,
            columns: [
                /*{
                    field: '',
                    title: '序号',
                    // sortable: true,
                    //  align: "center",
                    width: 60,
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },*/
                {
                    field: 'id',
                    title: '序号',
                    width: 50,
                    visible:false,
                },
                {
                    field: 'jdtj_id',
                    title: '商品编号',
                    width: 50,
                    //visible:false,
                },
                {
                    field: 'goodsName',
                    title: '商品名称',
                    width: 200,
                },
                {
                    field: 'goodsPicUrl',
                    title: '商品图片',
                    detailView : true,
                    width: 120,
                    formatter: function (value) {
                        let url = 'http://' + value;
                        console.log(url);
                        return '<img loading="lazy" src="'+ url +'" alt="Smiley face" width="100" height="100">'
                    }
                },
                {
                    field: 'goodsPrice',
                    title: '单价',
                    align: "right",
                    width: 50,

                },
                {
                    field: 'commission',
                    title: '佣金',
                    align: "right",
                    width: 50,
                },

                {
                    title: '操作',
                    align: 'center',
                    width: 100,
                    formatter: function(value, row, index) {
                        var actions = [];
                        /* actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodscode + '\')"><i class="fa fa-plus"></i>新增</a> ');row.sellNo + row.startTime + row.endTime*/
                        actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="jdReferralLink(\'' + row.referralLink +"','"+ row.createTime+ "','"+ row.goodsNum+ '\')"><i class="fa fa-edit"></i>京东</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        /* actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                        // actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        //actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                },


            ]
        };
        $.table.init(options_jd);

        var options = {
            id: "bootstrap-table-file",
            //url: ctx + "baodao/pay/jdtj" + "/list",
            url: ctx + "jd/file/list",
            toolbar:"toolbar",
            //createUrl: prefix + "/add/{id}",
            createUrl: ctx + "jd/global" +"/globalDetails",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",

            height: $(window).height()/2 ,
            /*  sortName: "companyId",*/
            modalName: "京东推荐",
            // 测试父子表
            detailView: false,
            clickEdit:true,
            //onEditableSave: onEditableSave,
            //onLoadSuccess: initSwitch(),
            columns: [
                {
                    field:'createTime',
                    title: '日期',
                },
                {
                    field: 'fileName',
                    title: '文件名',
                    //width:100
                },
                {
                    field: 'goodsNum',
                    title: '商品数量',
                    align: "right",
                    width:50
                },
                {
                    title: '操作',
                    align: 'center',
                    /* width: 100,*/
                    formatter: function(value, row, index) {
                        var actions = [];
                        /* actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodscode + '\')"><i class="fa fa-plus"></i>新增</a> ');row.sellNo + row.startTime + row.endTime*/
                        //actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.fileName +"','"+ row.createTime+ "','"+ row.goodsNum+ '\')"><i class="fa fa-edit"></i>选取1</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="queryJDTJDetails(\'' + row.fileName +"','"+ row.createTime+ "','"+ row.goodsNum+ '\')"><i class="fa fa-edit"></i>选取</a> ');
                        return actions.join('');
                    }
                },



            ],
        };
        $.table.init(options);



        //$('#bootstrap-table-jd').bootstrapTable(options_jd);


    });
</script>

<script>
    function  jdReferralLink(p1,p2,p3){
        console.log('京东推广链接：' + p1);
        window.open(p1)
        //$.table.refresh();
    }

    function queryJDTJDetails(p1,p2,p3) {


        console.log("查询小票明细： " + p1);
        if (p1 == null)
            //alert("小票号为空")
            // {
        {
            $.modal.alertWarning('小票号为空');
        }
        else {
            // p1 = "dkjfaldskfladskfjlas";
            console.log("弹窗展示交易明细")

            //var url = prefix +"/JDTJDetails/"  + p1;
            var url = ctx + "jd/global" +"/globalDetails/"  + p1+"?type=1" ;
            console.log("跳转页面： " + url)
            console.log("请求连接： " + url)
            table.set();
            $.modal.open('京东推荐商品',url,1200,800);
        }
    }



</script>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <!--            <div class="mt10 pt5">
                            <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的药品主治数据
                            &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
                        </div>-->
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“csv”格式文件！
            </font>
        </div>
    </form>
</script>


</body>
</html>
